package org.example.strategypatterndemo.module1.controller;

import org.example.strategypatterndemo.module1.OrderService;
import org.example.strategypatterndemo.module1.PromotionType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * TestController
 * @author dingchen
 * @version 2025/05/29 12:38
**/
@RestController
public class TestController {
    private final OrderService orderService;

    public TestController(OrderService orderService) {
        this.orderService = orderService;
    }

    /**
     * 测试接口
     * http://localhost:8080/calculate?orderAmount=300&promotionType=FULL_REDUCE
     */
    @GetMapping("/calculate")
    public String calculatePrice(@RequestParam double orderAmount, @RequestParam PromotionType promotionType) {
        double finalPrice = orderService.calculateFinalPrice(orderAmount, promotionType);

        return "订单金额：" + orderAmount + "元，使用" + promotionType.getDesc() + "后，最终价格：" + finalPrice + "元";
    }
}
